<?php

/**
 * Image state renderer for backend area
 */
class AW_Imagetest_Model_Form_Element_State extends Varien_Data_Form_Element_Text
{
    /**
     * Basical states ofvideoservices
     * @var array
     */
    protected $_states = array(
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_UNKNOWN, 'label' => 'Unknown', 'color' => 'black'),
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_PROCESSING, 'label' => 'Processing', 'color' => 'blue'),
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_READY, 'label' => 'Ready', 'color' => 'green'),
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_REJECTED, 'label' => 'Rejected', 'color' => 'red'),
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_FAILED, 'label' => 'Failed', 'color' => 'red'),
        array('value' => AW_Imagetest_Model_Image::IMAGE_STATE_DELETED, 'label' => 'Deleted', 'color' => 'red'),        
    );

    /**
     * Retrives translated and colored label
     * @param string $label Label
     * @param string $color Color of label
     * @return string
     */
    protected function _drawState($label, $color)
    {
        $label = Mage::helper('imagetest')->__($label);
        return "<strong style=\"color: {$color};\">{$label}</strong>";
    }
 
    /**
     * Retrives element html
     * @return string
     */
    public function getElementHtml()
    {
        $value = $this->getValue() ? $this->getValue() : 0;
        foreach ($this->_states as $state){
            if ($state['value'] == $value){
                return $this->_drawState($state['label'], $state['color']);
            }
        }
    }
}

